package cn.stylefeng.guns.modular.system.service;

import cn.stylefeng.guns.core.common.page.LayuiPageFactory;
import cn.stylefeng.guns.modular.system.entity.Brand;
import cn.stylefeng.guns.modular.system.mapper.BrandMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 品牌表 服务实现类
 * </p>
 *
 *
 * @since 2018-12-07
 */
@Service
public class BrandService extends ServiceImpl<BrandMapper, Brand> {

    @Resource
    private BrandMapper brandMapper;

    /**
     * 添加品牌
     */
    public void addDict(Brand brand) {

        this.addDictType(brand);
    }

    /**
     * 添加品牌类型
     */
    private void addDictType(Brand brand) {
        this.save(brand);
    }

    /**
     * 删除品牌
     */
    @Transactional
    public void delteDict(Long brandId) {
        //删除这个词典
        brandMapper.deleteById(brandId);
    }

    /**
     * 根据编码获取词典列表
     */
    public List<Brand> selectByCode(String code) {
        return this.baseMapper.selectByCode(code);
    }

    /**
     * 查询品牌列表
     */
    public Page<Map<String, Object>> list(String conditiion) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.list(page, conditiion);
    }

    public List<Brand> listNoPage() {
        return this.baseMapper.listNoPage();
    }
}
